<template>
  <div>
    <div class="menu_bar" @mouseleave="hidde">
      <el-row type="flex">
        <!-- 菜单栏显示部分 -->
        <el-col class="cityList">
          <div class="city" @mouseover="show(index)" v-for="(item,index) in postList" :key="index">
            <span>{{item.type}}</span>
            <i class="el-icon-arrow-right"></i>
          </div>
        </el-col>
        <!-- 菜单栏隐藏部分 -->
        <div class="menu_hidden" v-if="text.length > 0">
          <div
            class="city-list"
            v-for="(item,index) in text"
            :key="index"
            @click="sendCity(item.city)"
          >
            <span class="num">{{index + 1}}</span>
            <span class="city">{{item.city}}</span>
            <span class="text">{{item.desc}}</span>
          </div>
        </div>
      </el-row>
    </div>
    <div class="bottom">
      <h4>推荐城市</h4>
      <nuxt-link to="#">
        <img :src="url" alt />
      </nuxt-link>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      postList: [], // 列表数据
      text: [], //菜单栏隐藏显示部分
      url: require("static/pic_sea.jpeg")
    };
  },
  methods: {
    // 点击菜单触发
    sendCity(city) {
      this.$emit("sendCity", city);
    },
    // 鼠标离开时隐藏
    hidde() {
      this.text = [];
    },
    // 鼠标移入时显示
    show(index) {
      this.text = this.postList[index].children;
    }
  },
  mounted() {
    // 获取城市菜单列表
    this.$axios({
      url: "/posts/cities"
    }).then(res => {
      // console.log(res);
      const { data } = res.data;
      this.postList = data;
    });
  }
};
</script>

<style lang="less" scoped>
.menu_bar {
  position: relative;
  .cityList {
    width: 260px;
    border: 1px solid #ddd;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 0 1px #f5f5f5;
    z-index: 2;
    .city {
      position: relative;
      height: 40px;
      line-height: 40px;
      padding: 0 15px;
      border-bottom: 1px solid #ddd;
      border-right: 1px solid #ddd;
      font-size: 14px;
      z-index: 2;
      display: flex;
      justify-content: space-between;
      align-items: center;
      &:hover {
        color: #ffad00;
        border-right: none;
      }
      i {
        font-size: 20px;
        color: #acacac;
        width: 147px;
        text-align: right;
      }
    }
  }
  // 菜单隐藏样式
  .menu_hidden {
    border: 1px solid #ddd;
    padding: 8px 0;
    width: 364px;
    position: absolute;
    z-index: 2;
    left: 260px;
    box-shadow: 0 0 1px #f5f5f5;
    background: #fff;
    .city-list {
      padding: 8px 20px;
      cursor: pointer;
    }
    .num {
      color: #ffa500;
      font-style: italic;
      font-size: 18px;
    }
    .city {
      color: #ffa500;
      margin: 0 10px;
      font-size: 14px;
      &:hover {
        text-decoration: underline;
      }
    }
    .text {
      color: #999;
      font-size: 14px;
      &:hover {
        text-decoration: underline;
      }
    }
  }
}
.bottom {
  margin-top: 24px;
  h4 {
    font-weight: normal;
    width: 260px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
  }
  img {
    margin-top: 10px;
    width: 260px;
  }
}
</style>